ALLIANCE_TOP	= /opt/alliance-5.0
ENV_COUGAR	= MBK_SPI_MODEL=$(ALLIANCE_TOP)/etc/spimodel.cfg ;\
		  export MBK_SPI_MODEL;\
		  MBK_IN_PH=ap ;\
		  export MBK_IN_PH;\
		  MBK_OUT_LO=spi;\
		  export MBK_OUT_LO

ENV_ASIMUT	= MBK_CATAL_NAME=CATAL_ASIMUT

#***Ejecutar todos***#
all: toAlliance-all synthesis-all simulate-all place-route-all transistors-all

#***Convertir el modelo VHDL a Alliance***#
toAlliance-all: toAlliance-comparation_unit \
				toAlliance-dependency_selection \
				toAlliance-hazards_unit 

toAlliance-comparation_unit:
	vasy -Vaop -H comparation_unit	
toAlliance-dependency_selection:
	vasy -Vaop dependency_selection
toAlliance-hazards_unit: 
	vasy -Vaop -H hazards_unit

#***Simular el modelo***# 
#genpat => Genera archivo de patrones de entradas para simular a partir del .c =>.pat
#asimut => simula
#xpat   => Ver simulacion
simulate-all: simulate-comparation_unit\
				simulate-hazards_unit\
				simulate-dependency_selection \
				
simulate-comparation_unit: test_comparation_unit.c 
	genpat test_comparation_unit
	$(ENV_ASIMUT) asimut -b comparation_unit test_comparation_unit result_comparation_unit
view-simulate-comparation_unit:
	xpat -l result_comparation_unit

simulate-dependency_selection: test_dependency_selection.c 
	genpat test_dependency_selection
	$(ENV_ASIMUT) asimut -b dependency_selection test_dependency_selection result_dependency_selection
view-simulate-dependency_selection:
	xpat -l result_dependency_selection
	
simulate-hazards_unit: test_hazards_unit.c 
	genpat test_hazards_unit
	$(ENV_ASIMUT) asimut hazards_unit test_hazards_unit result_hazards_unit
view-simulate-hazards_unit:
	xpat -l result_hazards_unit

#***Sintesis***#
# boom => optimizar funciones logicas =>.vbe
# boog => generar el modelo estructural usando las celdas de alliance =>.vst y .xsc
# loon => optimiza el modelo estructural =>.vst
# xsch -I vst => visualizar el modelo estructural
synthesis-all: 	synthesis-comparation_unit\
				synthesis-dependency_selection\
				synthesis-hazards_unit

synthesis-comparation_unit: comparation_unit.vbe
	boom comparation_unit comparation_unit_boom	
	boog comparation_unit_boom comparation_unit
	loon -o comparation_unit
view-structural-comparation_unit:		
	xsch -I vst -l comparation_unit		

synthesis-dependency_selection: dependency_selection.vbe 
	boom dependency_selection dependency_selection_boom	
	boog dependency_selection_boom dependency_selection
	loon -o dependency_selection
view-structural-dependency_selection:		
	xsch -I vst -l dependency_selection		
		
synthesis-hazards_unit: comparation_unit.vbe dependency_selection.vbe hazards_unit_model.vbe
	boom hazards_unit_model hazards_unit_model
	boog hazards_unit_model hazards_unit_model
	loon -o hazards_unit_model
view-structural-hazards_unit:
	xsch -I vst -l hazards_unit

#***Place & Route***#
# ocp   => ubica celdas en su forma en el silicio =>.ap
# nero  => hace las conexiones entre las celdas buscando caminos optimos =>.ap
# s2r   => pasa del modelo simbolico al modelo real =>.cif
# graal => visualizar el modelo simbolico en el silicio
# dreal => visualizar el modelo real en el silicio
place-route-all: place-route-comparation_unit\
				place-route-dependency_selection\
				place-route-hazards_unit

place-route-comparation_unit: comparation_unit.vst
	ocp comparation_unit comparation_unit
	nero -p comparation_unit comparation_unit comparation_unit
	s2r comparation_unit comparation_unit_s2r
view-place-route-comparation_unit:
	graal -l comparation_unit
#	dreal -l comparation_unit_s2r

place-route-dependency_selection: dependency_selection.vst
	ocp dependency_selection dependency_selection
	nero -p dependency_selection dependency_selection dependency_selection
	s2r dependency_selection dependency_selection_s2r
view-place-route-dependency_selection:
	graal -l dependency_selection
#	dreal -l dependency_selection_s2r

place-route-hazards_unit: hazards_unit.vst
	ocp hazards_unit hazards_unit
	nero -p hazards_unit hazards_unit hazards_unit
	s2r hazards_unit hazards_unit_s2r
view-place-route-hazards_unit:
	graal -l hazards_unit
#	dreal -l hazards_unit_s2r

#**Transistors**#
# cougar => convierte a transistores en spi =>.spi
# xsch -I spi => visualizar el modelo en transistores transistores
transistors-all: transistors-comparation_unit\
	 transistors-dependency_selection\
	 transistors-hazards_unit

transistors-comparation_unit: comparation_unit.ap
	$(ENV_COUGAR); cougar -t comparation_unit comparation_unit_transistors 
view-transistors-comparation_unit:
	$(ENV_COUGAR); xsch -I spi -l comparation_unit_transistors

transistors-dependency_selection: dependency_selection.ap
	$(ENV_COUGAR); cougar -t dependency_selection dependency_selection_transistors 
view-transistors-dependency_selection:
	$(ENV_COUGAR); xsch -I spi -l dependency_selection_transistors

transistors-hazards_unit: hazards_unit.ap
	$(ENV_COUGAR); cougar -t hazards_unit hazards_unit_transistors 
view-transistors-hazards_unit:
	$(ENV_COUGAR); xsch -I spi -l hazards_unit_transistors


clean:
	rm -rf  *.pat \
		*.vst \
		*.xsc \
		*.vbe \
		*.boom \
		*.ap \
		*.cif \
		*.spi \
		*.dat
